package rpc

import (
	"context"
	"fmt"
	"gin-kitex-gorm/kitex_gen/user"
	"gin-kitex-gorm/kitex_gen/user/usersrv"
)

var UserClient usersrv.Client

func Register(c context.Context, req *user.UserRegisterRequest) (*user.UserRegisterResponse, error) {
	println("rpc.register")
	resp, err := UserClient.Register(c, req)
	if err != nil {
		return nil, err
	}
	if resp.StatusCode != 0 {
		return nil, fmt.Errorf("register error")
	}
	fmt.Printf("%#v", resp)
	return resp, nil
}

func Login(c context.Context, req *user.UserLoginRequest) (*user.UserLoginResponse, error) {
	println("rpc.login")
	resp, err := UserClient.Login(c, req)
	if err != nil {
		return nil, err
	}
	if resp.StatusCode != 0 {
		return nil, fmt.Errorf("login error")
	}
	fmt.Printf("%#v", resp)
	return resp, nil
}
